package ru.kradef.taxi.service;

import java.io.IOException;
import java.io.PrintStream;
import java.net.InetSocketAddress;

/**
 * Hello world!
 * 
 */
public class App implements HttpRequestHandler {
    public static void main(String[] args) throws Exception {
	HttpsServer httpsServer = new HttpsServer(InetSocketAddress.createUnresolved("0.0.0.0", 8888));
	char[] pass = "taksoparking".toCharArray();
	httpsServer.init("taksi.jks", pass, pass);
	httpsServer.accept(new App());

	httpsServer.close();
    }

    @Override
    public void service(HttpRequest request, HttpResponse response) {
	String html = "<html><body>Hello World!</body></html>";
	response.setContentLength(html.length());
	response.setContentType("text/html");

	PrintStream out = null;
	try {
	    out = new PrintStream(response.getOutputStream());
	    out.print(html);
	} catch (IOException e) {
	    // TODO Auto-generated catch block
	    e.printStackTrace();
	} finally {
	    if (out != null) {
		out.close();
	    }
	}

    }
}
